Skip to content

[AI] Add host model cache API surface#4302

Open
MatheMatrix wants to merge 5 commits into
feature-5.5.28-aiosfrom
sync/ye.zou/feature/ai-host-model-cache-control-plane@@3
Open

[AI] Add host model cache API surface#4302
MatheMatrix wants to merge 5 commits into
feature-5.5.28-aiosfrom
sync/ye.zou/feature/ai-host-model-cache-control-plane@@3

Conversation

@MatheMatrix

Copy link
Copy Markdown
Owner

Summary

  • Add host model cache schema rows for VM model-cache control-plane state.
  • Generate SDK actions/results/inventories and ApiHelper updates for host cache APIs.

Scope

  • VM/cloud-host model service deployment only.
  • Target branch: feature-5.5.28-aios.

Verification

  • ./runMavenProfile sdk
  • ./runMavenProfile apihelper
  • verify-case Docker AI module compile

Related premium/utility MRs use the same source branch suffix @@3.

sync from gitlab !10260

The VM model-cache feature needs persistent schema rows and generated client surfaces before premium can expose scheduling and cache-management controls.

Resolves: ZSTAC-0

Change-Id: I424f987899216872309b42439f8ba8a1353ae505
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@MatheMatrix, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 10 minutes. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: deedaa32-f666-4bb9-ab26-bf88c76875eb

📥 Commits

Reviewing files that changed from the base of the PR and between c9bc4e0 and 635921e.

📒 Files selected for processing (21)
  • conf/db/upgrade/V5.5.28__schema.sql
  • sdk/src/main/java/SourceClassMap.java
  • sdk/src/main/java/org/zstack/sdk/AiHostCacheStorageInventory.java
  • sdk/src/main/java/org/zstack/sdk/AiHostCacheStorageStatus.java
  • sdk/src/main/java/org/zstack/sdk/AiHostModelCacheFailureCode.java
  • sdk/src/main/java/org/zstack/sdk/AiHostModelCacheFailurePhase.java
  • sdk/src/main/java/org/zstack/sdk/AiHostModelCacheInventory.java
  • sdk/src/main/java/org/zstack/sdk/AiHostModelCachePolicyInventory.java
  • sdk/src/main/java/org/zstack/sdk/AiHostModelCacheStatus.java
  • sdk/src/main/java/org/zstack/sdk/CleanAiHostModelCacheAction.java
  • sdk/src/main/java/org/zstack/sdk/CleanAiHostModelCacheResult.java
  • sdk/src/main/java/org/zstack/sdk/GetAiHostModelCacheCapacityAction.java
  • sdk/src/main/java/org/zstack/sdk/GetAiHostModelCacheCapacityResult.java
  • sdk/src/main/java/org/zstack/sdk/QueryAiHostModelCacheAction.java
  • sdk/src/main/java/org/zstack/sdk/QueryAiHostModelCacheResult.java
  • sdk/src/main/java/org/zstack/sdk/RefreshAiHostModelCacheAction.java
  • sdk/src/main/java/org/zstack/sdk/RefreshAiHostModelCacheResult.java
  • sdk/src/main/java/org/zstack/sdk/UpdateAiHostModelCachePolicyAction.java
  • sdk/src/main/java/org/zstack/sdk/UpdateAiHostModelCachePolicyResult.java
  • sdk/src/main/java/org/zstack/sdk/VmModelMountInventory.java
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Could not fetch remote config from http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml: TimeoutError: The operation was aborted due to timeout
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

conf/db/upgrade/V5.5.28__schema.sql 中新增 4 张 AI Host Model Cache 相关表(AiHostModelCacheVOAiHostCacheStorageVOAiHostModelCachePolicyVOAiHostModelCacheReservationVO),均通过外键级联删除关联至 HostEO;并为 VmModelMountVO 添加可空列 cacheUuid 及对应外键(删除时置空)。

Changes

AI Host Model Cache Schema 迁移

Layer / File(s) Summary
新增 AI Host Model Cache 核心表
conf/db/upgrade/V5.5.28__schema.sql
新增 AiHostModelCacheVO(缓存元数据/状态/引用计数)、AiHostCacheStorageVO(存储容量与水位)、AiHostModelCachePolicyVO(策略配置)、AiHostModelCacheReservationVO(缓存预留记录)四张表,均含联合唯一约束/索引及对 HostEO(hostUuid) 的外键级联删除约束。
VmModelMountVO 关联缓存表
conf/db/upgrade/V5.5.28__schema.sql
VmModelMountVO 新增可空列 cacheUuid,创建索引 idxVmModelMountVOCacheUuid,并添加外键 fkVmModelMountVOAiHostModelCacheVO,当 AiHostModelCacheVO 记录被删除时将 cacheUuid 置空(SET NULL)。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 分钟

Poem

🐇 小兔翻开数据库的土地,
种下四张崭新的缓存表,
HostUuid 像根绳紧紧相系,
VmModelMount 轻轻指向缓存桥,
删之则空,聚则有序,
AI 模型的家园悄然筑起! 🌱


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Title check ❌ Error 标题不符合指定格式要求,缺少类型前缀(type)。格式应为 [scope]: ,但当前为 [AI] Add host model cache API surface。 修改标题格式为 [scope]: 的形式,例如 'feat[AI]: Add host model cache API surface',并确保不超过72字符。
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed 提供的描述与变更集相关,说明了所做更改的目的和验证方式。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/ye.zou/feature/ai-host-model-cache-control-plane@@3

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
conf/db/upgrade/V5.5.28__schema.sql (1)

198-200: ⚡ Quick win

存储过程参数中的表名/列名也建议使用反引号

当前 ADD_COLUMN/CREATE_INDEX/ADD_CONSTRAINT 的标识符参数是裸字符串;按仓库 SQL 规范,表名与列名应统一使用反引号包裹,避免关键字冲突或后续迁移不一致。

As per coding guidelines: “所有表名和列名必须使用反引号包裹(例如:WHERE system = 1),以避免 MySQL 8.0 / GreatSQL 保留关键字冲突导致的语法错误”。

建议修复示例
-CALL ADD_COLUMN('VmModelMountVO', 'cacheUuid', 'VARCHAR(32)', 1, NULL);
-CALL CREATE_INDEX('VmModelMountVO', 'idxVmModelMountVOCacheUuid', 'cacheUuid');
-CALL ADD_CONSTRAINT('VmModelMountVO', 'fkVmModelMountVOAiHostModelCacheVO', 'cacheUuid', 'AiHostModelCacheVO', 'uuid', 'SET NULL');
+CALL ADD_COLUMN('`VmModelMountVO`', '`cacheUuid`', 'VARCHAR(32)', 1, NULL);
+CALL CREATE_INDEX('`VmModelMountVO`', '`idxVmModelMountVOCacheUuid`', '`cacheUuid`');
+CALL ADD_CONSTRAINT('`VmModelMountVO`', '`fkVmModelMountVOAiHostModelCacheVO`', '`cacheUuid`', '`AiHostModelCacheVO`', '`uuid`', 'SET NULL');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@conf/db/upgrade/V5.5.28__schema.sql` around lines 198 - 200, All table names
and column names in the stored procedure calls ADD_COLUMN, CREATE_INDEX, and
ADD_CONSTRAINT must be wrapped with backticks to comply with the repository's
SQL coding standards and avoid conflicts with MySQL reserved keywords. Wrap the
following identifiers with backticks: 'VmModelMountVO', 'cacheUuid',
'idxVmModelMountVOCacheUuid', and 'AiHostModelCacheVO' in all three procedure
calls. This ensures consistency with the repository's SQL naming conventions and
prevents potential syntax errors with database engines like MySQL 8.0 or
GreatSQL.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@conf/db/upgrade/V5.5.28__schema.sql`:
- Around line 104-105: Remove the DEFAULT NULL clause and change these columns
to NOT NULL for all affected tables: `hostUuid` must be NOT NULL to enable
proper foreign key cascade deletion protection, and columns that are part of
unique constraints (identityHash and sourceRoot in their respective unique keys)
must also be NOT NULL to prevent MySQL from allowing multiple NULL values which
would violate the unique constraint semantics. Apply this change to hostUuid at
lines 104 and 127, and to identityHash/sourceRoot columns in their respective
unique key definitions throughout the schema file at the locations indicated.

---

Nitpick comments:
In `@conf/db/upgrade/V5.5.28__schema.sql`:
- Around line 198-200: All table names and column names in the stored procedure
calls ADD_COLUMN, CREATE_INDEX, and ADD_CONSTRAINT must be wrapped with
backticks to comply with the repository's SQL coding standards and avoid
conflicts with MySQL reserved keywords. Wrap the following identifiers with
backticks: 'VmModelMountVO', 'cacheUuid', 'idxVmModelMountVOCacheUuid', and
'AiHostModelCacheVO' in all three procedure calls. This ensures consistency with
the repository's SQL naming conventions and prevents potential syntax errors
with database engines like MySQL 8.0 or GreatSQL.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 3af6b300-8d45-46a2-8818-bb73ee532b92

📥 Commits

Reviewing files that changed from the base of the PR and between c6344f8 and 8313936.

⛔ Files ignored due to path filters (19)
  • sdk/src/main/java/SourceClassMap.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/AiHostCacheStorageInventory.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/AiHostCacheStorageStatus.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/AiHostModelCacheFailureCode.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/AiHostModelCacheFailurePhase.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/AiHostModelCacheInventory.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/AiHostModelCachePolicyInventory.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/AiHostModelCacheStatus.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/CleanAiHostModelCacheAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/CleanAiHostModelCacheResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/GetAiHostModelCacheCapacityAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/GetAiHostModelCacheCapacityResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/QueryAiHostModelCacheAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/QueryAiHostModelCacheResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/RefreshAiHostModelCacheAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/RefreshAiHostModelCacheResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UpdateAiHostModelCachePolicyAction.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/UpdateAiHostModelCachePolicyResult.java is excluded by !sdk/**
  • sdk/src/main/java/org/zstack/sdk/VmModelMountInventory.java is excluded by !sdk/**
📒 Files selected for processing (2)
  • conf/db/upgrade/V5.5.28__schema.sql
  • testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy

Comment thread conf/db/upgrade/V5.5.28__schema.sql Outdated
Host model cache identity and reservation lifecycle fields must be non-null to keep database uniqueness and capacity accounting consistent with the premium VO model.

Resolves: ZSTAC-0

Change-Id: Ibbc18ef1436e3ec8366b38c055451fc610fff88a
host cache storage and policy rows are keyed by hostUuid/sourceRoot and are removed through host cascade, so the DDL now rejects null key components instead of relying on nullable unique-key behavior.

Resolves: ZSTAC-0

Change-Id: If75425fc43b3ba407b807c7440fe1982b376cf9e
Regenerated ApiHelper after adding host model cache API actions.

Resolves: ZSTAC-0

Change-Id: Ic04457599d0e3d3e59d26a7a22156b6785d3e913
@MatheMatrix MatheMatrix force-pushed the sync/ye.zou/feature/ai-host-model-cache-control-plane@@3 branch from 6ea6aeb to 7c888ad Compare June 22, 2026 04:51
Regenerated SDK in verify-case with the premium host model cache branch mounted so update_sdk stays clean.

Tested: verify-case ./runMavenProfile premium
Tested: verify-case ./runMavenProfile sdk

Resolves: ZSTAC-0

Change-Id: I42c8e3c0edc320588097236dc8d207ebfcb8cdce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants